package com.ternnetwork.core.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.PrintWriterUtils;
import com.ternnetwork.core.entity.Role;
import com.ternnetwork.core.service.RoleService;
import com.ternnetwork.persistence.page.Page;




@Controller
@RequestMapping("/core/role/*")
public class RoleController {
	
	@Resource
	private RoleService roleService;
	
	@RequestMapping("manage.htm")
	public ModelAndView manage(){
		return new ModelAndView("/WEB-INF/view/core/role_manage.jsp");
	}
	
	
	@RequestMapping("add.htm")
	public @ResponseBody BaseResponse add(Role t){
		return roleService.idoAdd(t);
	}
	
	@RequestMapping("update.htm")
	public  @ResponseBody BaseResponse update(Role t){
		return roleService.idoUpdate(t);
	}
	
	@RequestMapping("delete.htm")
	public  @ResponseBody BaseResponse delete(long id){
		return roleService.idoDelete(id);
	}
	
	@RequestMapping("query.htm")
	public void query(PrintWriter out,HttpServletResponse response,String sort,String order,int limit, int offset){
		Page page=Page.createPage(limit, offset);
		PrintWriterUtils.printString(out, response, roleService.query(page));
	}
	
	@RequestMapping("findAll.htm")
	public  @ResponseBody List<Role> findAllRole(){
		return roleService.findAll("from Role");
	}
	
}
